<!DOCTYPE html>

































































<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="shortcut icon" type="image/x-icon" href="../../../favicon.ico" />
<title>Copy and Paste | Android Developers</title>
<link href="../../../assets/android-developer-docs-devguide.css" rel="stylesheet" type="text/css" />
<script src="../../../assets/search_autocomplete.js" type="text/javascript"></script>
<script src="../../../assets/jquery-resizable.min.js" type="text/javascript"></script>
<script src="../../../assets/android-developer-docs.js" type="text/javascript"></script>
<script src="../../../assets/prettify.js" type="text/javascript"></script>
<script type="text/javascript">
  setToRoot("../../../");
</script>
<noscript>
  <style type="text/css">
    html,body{overflow:auto;}
    #body-content{position:relative; top:0;}
    #doc-content{overflow:visible;border-left:3px solid #666;}
    #side-nav{padding:0;}
    #side-nav .toggle-list ul {display:block;}
    #resize-packages-nav{border-bottom:3px solid #666;}
  </style>
</noscript>
</head>
<body class="gc-documentation">

  <div id="header">
      <div id="headerLeft">
          <a href="../../../index.html" tabindex="-1"><img
              src="../../../assets/images/bg_logo.png" alt="Android Developers" /></a>
          <ul id="header-tabs" class="guide">
    
	<li id="home-link"><a href="../../../offline.html">
	
		<span class="en">Home</span>
		<span style="display:none" class="de">Startseite</span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ホーム</span>
		<span style="display:none" class="zh-CN">主页</span>
		<span style="display:none" class="zh-TW">首頁</span>
	
	</a></li>
	<li id="sdk-link"><a href="../../../sdk/index.html">
		<span class="en">SDK</span>
	</a></li>
	<li id="guide-link"><a href="../../../guide/index.html" onClick="return loadLast('guide')">
	
		<span class="en">Dev Guide</span>
		<span style="display:none" class="de">Handbuch</span>
		<span style="display:none" class="es">Guía</span>
		<span style="display:none" class="fr">Guide</span>
		<span style="display:none" class="it">Guida</span>
		<span style="display:none" class="ja">開発ガイド</span>
		<span style="display:none" class="zh-CN">开发人员指南</span>
		<span style="display:none" class="zh-TW">開發指南</span>
	
	</a></li>
	<li id="reference-link"><a href="../../../reference/packages.html" onClick="return loadLast('reference')">
	
		<span class="en">Reference</span>
		<span style="display:none" class="de">Referenz</span>
		<span style="display:none" class="es">Referencia</span>
		<span style="display:none" class="fr">Référence</span>
		<span style="display:none" class="it">Riferimento</span>
		<span style="display:none" class="ja">リファレンス</span>
		<span style="display:none" class="zh-CN">参考</span>
		<span style="display:none" class="zh-TW">參考資料</span>
	
	</a></li>
	<li id="resources-link"><a href="../../../resources/index.html" onClick="return loadLast('resources')">
	
		<span class="en">Resources</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
    		<span style="display:none" class="ja"></span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li id="videos-link"><a href="../../../videos/index.html" onClick="return loadLast('videos')">
	
		<span class="en">Videos</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ビデオ</span>
		<span style="display:none" class="zh-CN"></span>
		<span style="display:none" class="zh-TW"></span>
	
	</a></li>
	<li><a href="http://android-developers.blogspot.com" onClick="return requestAppendHL(this.href)">
	
		<span class="en">Blog</span>
		<span style="display:none" class="de"></span>
		<span style="display:none" class="es"></span>
		<span style="display:none" class="fr"></span>
		<span style="display:none" class="it"></span>
		<span style="display:none" class="ja">ブログ</span>
		<span style="display:none" class="zh-CN">博客</span>
		<span style="display:none" class="zh-TW">網誌</span>
	
	</a></li>


     
</ul>
     
      </div>
      <div id="headerRight">
          <div id="headerLinks">
          
          <a href="http://www.android.com">Android.com</a>
          </div>
  <div id="search" >
      <div id="searchForm">
          <form accept-charset="utf-8" class="gsc-search-box" 
                onsubmit="return submit_search()">
            <table class="gsc-search-box" cellpadding="0" cellspacing="0"><tbody>
                <tr>
                  <td class="gsc-input">
                    <input id="search_autocomplete" class="gsc-input" type="text" size="33" autocomplete="off"
                      title="search developer docs" name="q"
                      value="search developer docs"
                      onFocus="search_focus_changed(this, true)"
                      onBlur="search_focus_changed(this, false)"
                      onkeydown="return search_changed(event, true, '../../../')"
                      onkeyup="return search_changed(event, false, '../../../')" />
                  <div id="search_filtered_div" class="no-display">
                      <table id="search_filtered" cellspacing=0>
                      </table>
                  </div>
                  </td>
                  <td class="gsc-search-button">
                    <input type="submit" value="Search" title="search" id="search-button" class="gsc-search-button" />
                  </td>
                  <td class="gsc-clear-button">
                    <div title="clear results" class="gsc-clear-button">&nbsp;</div>
                  </td>
                </tr></tbody>
              </table>
          </form>
      </div><!-- searchForm -->
  </div><!-- search -->
      </div><!-- headerRight -->
      <script type="text/javascript">
        <!--  
        changeTabLang(getLangPref());
        //-->
      </script>
  </div><!-- header -->

  <div class="g-section g-tpl-240" id="body-content">
    <div class="g-unit g-first" id="side-nav">
      <div id="devdoc-nav">
<ul>

  <li>
    <h2><span class="en">Android Basics</span>
        <span class="de" style="display:none">Einführung in Android</span>
        <span class="es" style="display:none">Información básica sobre Android</span>
        <span class="fr" style="display:none">Présentation d'Android</span>
        <span class="it" style="display:none">Nozioni di base su Android</span>
        <span class="ja" style="display:none">Android の基本</span>
        <span class="zh-CN" style="display:none">Android 基础知识</span>
        <span class="zh-TW" style="display:none">Android 簡介</span>
    </h2>
    <ul>
      <li><a href="../../../guide/basics/what-is-android.html">
        <span class="en">What Is Android?</span>
        <span class="de" style="display:none">Was ist Android?</span>
        <span class="es" style="display:none">¿Qué es Android?</span>
        <span class="fr" style="display:none">Qu'est-ce qu'Android&nbsp;?</span>
        <span class="it" style="display:none">Che cos'è Android?</span>
        <span class="ja" style="display:none">Android とは</span>
        <span class="zh-CN" style="display:none">Android 是什么？</span>
        <span class="zh-TW" style="display:none">什麼是 Android？</span>
          </a></li>
      <li><a href="../../../guide/topics/fundamentals.html">
        <span class="en">Application Fundamentals</span>
        <span class="de" style="display:none">Anwendungsgrundlagen</span>
        <span class="es" style="display:none">Fundamentos de las aplicaciones</span>
        <span class="fr" style="display:none">Principes de base des applications</span>
        <span class="it" style="display:none">Concetti fondamentali sulle applicazioni</span>
        <span class="ja" style="display:none">開発の基礎</span>
        <span class="zh-CN" style="display:none">应用程序基础</span>
        <span class="zh-TW" style="display:none">應用程式基本原理</span>
      </a></li>

  <!--  <li><a style="color:gray;">The Android SDK</a></li> -->
  <!--  <li><a style="color:gray;">Walkthrough for Developers</a></li> -->
      <!-- quick overview of what it's like to develop on Android -->
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Framework Topics</span>
      <span class="de" style="display:none">Framework-Themen</span>
      <span class="es" style="display:none">Temas sobre el framework</span>
      <span class="fr" style="display:none">Thèmes relatifs au framework</span>
      <span class="it" style="display:none">Argomenti relativi al framework</span>
      <span class="ja" style="display:none">フレームワーク トピック</span>
      <span class="zh-CN" style="display:none">框架主题</span>
      <span class="zh-TW" style="display:none">架構主題</span>
    </h2>
    <ul>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/fundamentals/activities.html">
          <span class="en">Activities</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/fundamentals/fragments.html">
            <span class="en">Fragments</span>
          </a></li>
          <li><a href="../../../guide/topics/fundamentals/loaders.html">
            <span class="en">Loaders</span>
          </a></li>
          <li><a href="../../../guide/topics/fundamentals/tasks-and-back-stack.html">
            <span class="en">Tasks and Back Stack</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/fundamentals/services.html">
          <span class="en">Services</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/fundamentals/bound-services.html">
            <span class="en">Bound Services</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/topics/providers/content-providers.html">
            <span class="en">Content Providers</span>
          </a></li>
      <li><a href="../../../guide/topics/intents/intents-filters.html">
            <span class="en">Intents and Intent Filters</span>
          </a></li>
      <li><a href="../../../guide/topics/fundamentals/processes-and-threads.html">
            <span class="en">Processes and Threads</span>
          </a></li>
    </ul>


    <ul>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/ui/index.html">
            <span class="en">User Interface</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/topics/ui/declaring-layout.html">
               <span class="en">XML Layouts</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/ui-events.html">
                <span class="en">Input Events</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/menus.html">
               <span class="en">Menus</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/actionbar.html">
               <span class="en">Action Bar</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/dialogs.html">
                <span class="en">Dialogs</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/topics/ui/notifiers/index.html">
                <span class="en">Notifications</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/topics/ui/notifiers/toasts.html">
                <span class="en">Toast Notifications</span>
              </a></li>
              <li><a href="../../../guide/topics/ui/notifiers/notifications.html">
                <span class="en">Status Bar Notifications</span>
              </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/topics/ui/drag-drop.html">
                <span class="en">Drag and Drop</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/themes.html">
                <span class="en">Styles and Themes</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/custom-components.html">
                <span class="en">Custom Components</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/binding.html">
                <span class="en">Binding to Data with AdapterView</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/layout-objects.html">
                <span class="en">Common Layout Objects</span>
              </a></li>
          <li><a href="../../../guide/topics/ui/how-android-draws.html">
                <span class="en">How Android Draws Views</span>
              </a></li>
        </ul>
      </li><!-- end of User Interface -->

      <li class="toggle-list">
        <div><a href="../../../guide/topics/resources/index.html">
               <span class="en">Application Resources</span>
             </a></div>
        <ul>
          <li><a href="../../../guide/topics/resources/providing-resources.html">
                <span class="en">Providing Resources</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/accessing-resources.html">
                <span class="en">Accessing Resources</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/runtime-changes.html">
                <span class="en">Handling Runtime Changes</span>
              </a></li>
          <li><a href="../../../guide/topics/resources/localization.html">
                <span class="en">Localization</span>
              </a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/topics/resources/available-resources.html">
              <span class="en">Resource Types</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/topics/resources/animation-resource.html">Animation</a></li>
              <li><a href="../../../guide/topics/resources/color-list-resource.html">Color State List</a></li>
              <li><a href="../../../guide/topics/resources/drawable-resource.html">Drawable</a></li>
              <li><a href="../../../guide/topics/resources/layout-resource.html">Layout</a></li>
              <li><a href="../../../guide/topics/resources/menu-resource.html">Menu</a></li>
              <li><a href="../../../guide/topics/resources/string-resource.html">String</a></li>
              <li><a href="../../../guide/topics/resources/style-resource.html">Style</a></li>
              <li><a href="../../../guide/topics/resources/more-resources.html">More Types</a></li>
            </ul>
          </li><!-- end of resource types -->
        </ul>
      </li><!-- end of app resources -->
      <li class="toggle-list">
        <div><a href="../../../guide/topics/data/data-storage.html">
            <span class="en">Data Storage</span>
          </a></div>
          <ul>
            <li><a href="../../../guide/topics/data/backup.html">
                <span class="en">Data Backup</span>
              </a>
            </li>
          </ul>
      </li>
      <li><a href="../../../guide/topics/security/security.html">
            <span class="en">Security and Permissions</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/manifest/manifest-intro.html">
          <span class="en">The AndroidManifest.xml File</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/topics/manifest/action-element.html">&lt;action&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/activity-element.html">&lt;activity&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/activity-alias-element.html">&lt;activity-alias&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/application-element.html">&lt;application&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/category-element.html">&lt;category&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/compatible-screens-element.html">&lt;compatible-screens&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/data-element.html">&lt;data&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/grant-uri-permission-element.html">&lt;grant-uri-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/instrumentation-element.html">&lt;instrumentation&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/intent-filter-element.html">&lt;intent-filter&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/manifest-element.html">&lt;manifest&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/meta-data-element.html">&lt;meta-data&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/path-permission-element.html">&lt;path-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-element.html">&lt;permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-group-element.html">&lt;permission-group&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/permission-tree-element.html">&lt;permission-tree&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/provider-element.html">&lt;provider&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/receiver-element.html">&lt;receiver&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/service-element.html">&lt;service&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/supports-gl-texture-element.html">&lt;supports-gl-texture&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/supports-screens-element.html">&lt;supports-screens&gt;</a></li><!-- ##api level 4## -->
          <li><a href="../../../guide/topics/manifest/uses-configuration-element.html">&lt;uses-configuration&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-feature-element.html">&lt;uses-feature&gt;</a></li> <!-- ##api level 4## -->
          <li><a href="../../../guide/topics/manifest/uses-library-element.html">&lt;uses-library&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-permission-element.html">&lt;uses-permission&gt;</a></li>
          <li><a href="../../../guide/topics/manifest/uses-sdk-element.html">&lt;uses-sdk&gt;</a></li>
        </ul>
      </li><!-- end of the manifest file -->
    </ul>

    <ul>
    <li class="toggle-list">
        <div><a href="../../../guide/topics/graphics/index.html">
            <span class="en">Graphics</span>
          </a><span class="new-child">new!</span></div>
        <ul>
          <li><a href="../../../guide/topics/graphics/2d-graphics.html">
              <span class="en">Canvas and Drawables</span></a></li>
          <li><a href="../../../guide/topics/graphics/hardware-accel.html">
              <span class="en">Hardware Acceleration</span></a>
            <span class="new">new!</span></li>
          <li><a href="../../../guide/topics/graphics/opengl.html">
              <span class="en">OpenGL</span>
            </a><span class="new">updated</span></li>
        </ul>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/graphics/animation.html">
            <span class="en">Animation</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/topics/graphics/prop-animation.html">
              <span class="en">Property Animation</span></a></li>
          <li><a href="../../../guide/topics/graphics/view-animation.html">
              <span class="en">View Animation</span></a></li>
          <li><a href="../../../guide/topics/graphics/drawable-animation.html">
              <span class="en">Drawable Animation</span></a></li>
        </ul>
      </li>
      <li class="toggle-list">
	        <div><a href="../../../guide/topics/renderscript/index.html">
	            <span class="en">RenderScript</span>
	          </a></div>
	        <ul>
	          <li><a href="../../../guide/topics/renderscript/graphics.html">
	                <span class="en">Graphics</span>
	              </a>
	          </li>
	          <li><a href="../../../guide/topics/renderscript/compute.html">
	                <span class="en">Compute</span>
	              </a>
	          </li>
	        </ul>
  	  </li>

      <li class="toggle-list">
          <div><a href="../../../guide/topics/media/index.html">
            <span class="en">Multimedia and Camera</span>
          </a><span class="new">updated</span></div>
          <ul>
            <li><a href="../../../guide/topics/media/mediaplayer.html">
                  <span class="en">Media Playback</span></a>
                </li>
            <li><a href="../../../guide/topics/media/jetplayer.html">
                  <span class="en">JetPlayer</span></a>
                </li>
            <li><a href="../../../guide/topics/media/camera.html">
                  <span class="en">Camera</span></a>
                  <span class="new">new!</span>
                </li>
            <li><a href="../../../guide/topics/media/audio-capture.html">
                  <span class="en">Audio Capture</span></a>
                </li>
          </ul>
      </li>
      <li>
        <a href="../../../guide/topics/clipboard/copy-paste.html">
            <span class="en">Copy and Paste</span>
        </a></li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Sensors</a></div>
          <ul>
            <li><a style="color:gray;">Camera</a></li>
            <li><a style="color:gray;">Compass</a></li>
            <li><a style="color:gray;">Accelerometer</a></li>
          </ul>
      </li> -->
      <li class="toggle-list">
        <div><a href="../../../guide/topics/location/index.html">
               <span class="en">Location and Maps</span>
             </a></div>
        <ul>
          <li><a href="../../../guide/topics/location/obtaining-user-location.html">
                <span class="en">Obtaining User Location</span>
              </a></li>
        </ul>
      </li>
  <!--<li class="toggle-list">
        <div><a style="color:gray;">Wireless Controls</a></div>
          <ul>
            <li><a style="color:gray;">Wi-Fi</a></li>
          </ul>
      </li> -->
  <!--<li><a style="color:gray;">Localization</a></li>  -->
      <li><a href="../../../guide/topics/appwidgets/index.html">
            <span class="en">App Widgets</span></a>
          </li>
      <li><a href="../../../guide/topics/wireless/bluetooth.html">
            <span class="en">Bluetooth</span></a>
          </li>
      <li><a href="../../../guide/topics/nfc/index.html">
            <span class="en">Near Field Communication</span>
          </a></li>
      <li class="toggle-list">
          <div><a href="../../../guide/topics/usb/index.html">
            <span class="en">USB</span></a>
          </div>
            <ul>
              <li><a href="../../../guide/topics/usb/accessory.html">Accessory</a></li>
              <li><a href="../../../guide/topics/usb/host.html">Host</a></li>
              <li><a href="../../../guide/topics/usb/adk.html">Open Accessory Dev Kit</a></li>
            </ul>
          </li>

       <li><a href="../../../guide/topics/network/sip.html">
            <span class="en">Session Initiation Protocol</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/topics/search/index.html">
            <span class="en">Search</span>
          </a></div>
          <ul>
            <li><a href="../../../guide/topics/search/search-dialog.html">Creating a Search Interface</a></li>
            <li><a href="../../../guide/topics/search/adding-recent-query-suggestions.html">Adding Recent Query Suggestions</a></li>
            <li><a href="../../../guide/topics/search/adding-custom-suggestions.html">Adding Custom Suggestions</a></li>
            <li><a href="../../../guide/topics/search/searchable-config.html">Searchable Configuration</a></li>
          </ul>
      </li>
      <li><a href="../../../guide/topics/admin/device-admin.html">
            <span class="en">Device Administration</span></a>
      </li>
      <li class="toggle-list">
           <div>
                <a href="../../../guide/topics/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../../guide/topics/testing/testing_android.html">
                <span class="en">Testing Fundamentals</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/activity_testing.html">
                <span class="en">Activity Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/contentprovider_testing.html">
                <span class="en">Content Provider Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/service_testing.html">
                <span class="en">Service Testing</span></a>
              </li>
              <li>
                <a href="../../../guide/topics/testing/what_to_test.html">
                <span class="en">What To Test</span></a>
              </li>
           </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2>
      <span class="en">Android Market Topics</span>
    </h2>
    <ul>
      <li><a href="../../../guide/publishing/licensing.html">
          <span class="en">Application Licensing</span></a>
      </li>
      <li class="toggle-list">
        <div><a href="../../../guide/market/billing/index.html">
            <span class="en">In-app Billing</span></a>
        </div>
        <ul>
          <li><a href="../../../guide/market/billing/billing_overview.html">
              <span class="en">In-app Billing Overview</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_integrate.html">
              <span class="en">Implementing In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_best_practices.html">
              <span class="en">Security and Design</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_testing.html">
              <span class="en">Testing In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_admin.html">
              <span class="en">Administering In-app Billing</span></a>
          </li>
          <li><a href="../../../guide/market/billing/billing_reference.html">
              <span class="en">In-app Billing Reference</span></a>
          </li>
        </ul>
      </li>
      <li><a href="../../../guide/appendix/market-filters.html">
          <span class="en">Market Filters</span></a>
      </li>
      <li><a href="../../../guide/market/publishing/multiple-apks.html">
          <span class="en">Multiple APK Support</span></a>
      </li>
    </ul>
  </li>


  <li>
    <h2><span class="en">Developing</span>
               <span class="de" style="display:none">Entwicklung</span>
               <span class="es" style="display:none">Desarrollo</span>
               <span class="fr" style="display:none">Développement</span>
               <span class="it" style="display:none">Sviluppo</span>
               <span class="ja" style="display:none">開発</span>
               <span class="zh-CN" style="display:none">开发</span>
               <span class="zh-TW" style="display:none">開發</span>
    </h2>
    <ul>
  <!--<li><a href="">Developing for Android</a></li>
      signing, upgrading, selecting a package name, select device profile, touch, trackball, dpad available, etc. -->
      <li>
        <a href="../../../guide/developing/index.html">
        <span class="en">Introduction</span></a>
      </li>

      <li class="toggle-list">
        <div>
           <a href="../../../guide/developing/devices/index.html">
                <span class="en">Managing Virtual Devices</span>
            </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/devices/managing-avds.html">
              <span class="en">With AVD Manager</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/devices/managing-avds-cmdline.html">
              <span class="en">From the Command Line</span>
            </a>
          </li>
          <li>
           <a href="../../../guide/developing/devices/emulator.html">
                <span class="en">Using the Android Emulator</span>
            </a>
          </li>
        </ul>
      </li>
      <li>
        <a href="../../../guide/developing/device.html">
          <span class="en">Using Hardware Devices</span>
        </a>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/projects/index.html">
            <span class="en">Managing Projects</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/projects/projects-eclipse.html">
              <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/projects/projects-cmdline.html">
                <span class="en">From the Command Line</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/building/index.html">
            <span class="en">Building and Running</span>
          </a>
        </div>
        <ul>
          <li><a href="../../../guide/developing/building/building-eclipse.html">
            <span class="en">From Eclipse with ADT</span>
          </a></li>
          <li><a href="../../../guide/developing/building/building-cmdline.html">
            <span class="en">From the Command Line</span></a></li>
        </ul>
      </li>

      <li class="toggle-list">
        <div>
          <a href="../../../guide/developing/debugging/index.html">
            <span class="en">Debugging</span>
          </a>
        </div>
        <ul>
          <li>
            <a href="../../../guide/developing/debugging/debugging-projects.html">
                <span class="en">From Eclipse with ADT</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-projects-cmdline.html">
                <span class="en">From Other IDEs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/ddms.html">
              <span class="en">Using DDMS</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-log.html">
                <span class="en">Reading and Writing Logs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-ui.html">
                <span class="en">Debugging and Profiling UIs</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-tracing.html">
                <span class="en">Profiling with Traceview and dmtracedump</span>
            </a>
          </li>
          <li>
            <a href="../../../guide/developing/debugging/debugging-devtools.html">
                <span class="en">Using the Dev Tools App</span>
            </a>
          </li>
        </ul>
      </li>

      <li class="toggle-list">
           <div>
                <a href="../../../guide/developing/testing/index.html">
                   <span class="en">Testing</span>
               </a>
           </div>
           <ul>
              <li>
                <a href="../../../guide/developing/testing/testing_eclipse.html">
                  <span class="en">From Eclipse with ADT</span>
                </a>
              </li>

              <li>
                <a href="../../../guide/developing/testing/testing_otheride.html">
                  <span class="en">From Other IDEs</span>
                </a>
              </li>
           </ul>
         </li>

         <li class="toggle-list">
        <div><a href="../../../guide/developing/tools/index.html">
            <span class="en">Tools</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/developing/tools/adb.html">adb</a></li>
          <li><a href="../../../guide/developing/tools/adt.html">ADT</a></li>
          <li><a href="../../../guide/developing/tools/android.html">android</a></li>
          <li><a href="../../../guide/developing/tools/bmgr.html">bmgr</a>
          <li><a href="../../../guide/developing/tools/dmtracedump.html">dmtracedump</a></li>
          <li><a href="../../../guide/developing/tools/draw9patch.html">Draw
          9-Patch</a></li>
          <li><a href="../../../guide/developing/tools/emulator.html">Emulator</a></li>
          <li><a href="../../../guide/developing/tools/etc1tool.html">etc1tool</a></li>
          <li><a href="../../../guide/developing/tools/hierarchy-viewer.html">Hierarchy Viewer</a></li>
          <li><a href="../../../guide/developing/tools/hprof-conv.html">hprof-conv</a></li>
          <li><a href="../../../guide/developing/tools/layoutopt.html">layoutopt</a></li>
          <li><a href="../../../guide/developing/tools/logcat.html">logcat</a></li>
          <li><a href="../../../guide/developing/tools/mksdcard.html">mksdcard</a></li>
          <li><a href="../../../guide/developing/tools/monkey.html">Monkey</a></li>
          <li class="toggle-list">
            <div><a href="../../../guide/developing/tools/monkeyrunner_concepts.html">
              <span class="en">monkeyrunner</span>
            </a></div>
            <ul>
              <li><a href="../../../guide/developing/tools/MonkeyDevice.html">
                <span class="en">MonkeyDevice</span>
                </a></li>
              <li><a href="../../../guide/developing/tools/MonkeyImage.html">
                <span class="en">MonkeyImage</span>
                </a></li>
              <li><a href="../../../guide/developing/tools/MonkeyRunner.html">
                <span class="en">MonkeyRunner</span>
                </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/developing/tools/proguard.html">ProGuard</a></li>
          <li><a href="../../../guide/developing/tools/adb.html#sqlite">sqlite3</a></li>
          <li><a href="../../../guide/developing/tools/traceview.html">Traceview</a></li>
          <li><a href="../../../guide/developing/tools/zipalign.html">zipalign</a></li>
        </ul>
      </li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Publishing</span>
        <span class="de" style="display:none">Veröffentlichung</span>
        <span class="es" style="display:none">Publicación</span>
        <span class="fr" style="display:none">Publication</span>
        <span class="it" style="display:none">Pubblicazione</span>
        <span class="ja" style="display:none">公開</span>
        <span class="zh-CN" style="display:none">发布</span>
        <span class="zh-TW" style="display:none">發佈</span>
    </h2>
    <ul>
      <li><a href="../../../guide/publishing/app-signing.html">
            <span class="en">Signing Your Applications</span>
            <span class="de" style="display:none">Signieren Ihrer Anwendungen</span>
            <span class="es" style="display:none">Firma de aplicaciones</span>
            <span class="fr" style="display:none">Attribution de votre signature <br />à vos applications</span>
            <span class="it" style="display:none">Firma delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションへの署名</span>
            <span class="zh-CN" style="display:none">应用程序签名</span>
            <span class="zh-TW" style="display:none">簽署應用程式</span>
          </a></li>
      <li><a href="../../../guide/publishing/versioning.html">
            <span class="en">Versioning Your Applications</span>
            <span class="de" style="display:none">Versionsverwaltung für Ihre <br />Anwendungen</span>
            <span class="es" style="display:none">Versiones de las aplicaciones</span>
            <span class="fr" style="display:none">Attribution d'une version à vos applications</span>
            <span class="it" style="display:none">Controllo versioni delle applicazioni</span>
            <span class="ja" style="display:none">アプリケーションのバージョニング</span>
            <span class="zh-CN" style="display:none">应用程序版本控制</span>
            <span class="zh-TW" style="display:none">應用程式版本設定</span>
          </a></li>
      <li><a href="../../../guide/publishing/preparing.html">
            <span class="en">Preparing to Publish</span>
            <span class="de" style="display:none">Vorbereitung auf die Veröffentlichung</span>
            <span class="es" style="display:none">Publicación de aplicaciones</span>
            <span class="fr" style="display:none">Préparation à la publication</span>
            <span class="it" style="display:none">Preparativi per la pubblicazione</span>
            <span class="ja" style="display:none">公開の準備</span>
            <span class="zh-CN" style="display:none">准备发布</span>
            <span class="zh-TW" style="display:none">準備發佈</span>
          </a></li>
      <li><a href="../../../guide/publishing/publishing.html">
            <span class="en">Publishing on Android Market</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Best Practices</span>
               <span class="de" style="display:none">Bewährte Verfahren</span>
               <span class="es" style="display:none">Prácticas recomendadas</span>
               <span class="fr" style="display:none">Meilleures pratiques</span>
               <span class="it" style="display:none">Best practice</span>
               <span class="ja" style="display:none">ベスト プラクティス</span>
               <span class="zh-CN" style="display:none">最佳实践</span>
               <span class="zh-TW" style="display:none">最佳實務</span>
    </h2>
    <ul>
      <li><a href="../../../guide/practices/compatibility.html">
            <span class="en">Compatibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/screens_support.html">
          <span class="en">Supporting Multiple Screens</span>
        </a></div>
        <ul>
          <li><a href="../../../guide/practices/screens-distribution.html">
            <span class="en">Distributing to Specific Screens</span>
          </a></li>
          <li><a href="../../../guide/practices/screen-compat-mode.html">
            <span class="en">Screen Compatibility Mode</span>
          </a></li>
          <li><a href="../../../guide/practices/screens-support-1.5.html">
            <span class="en">Strategies for Android 1.5</span>
          </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/practices/optimizing-for-3.0.html">
            <span class="en">Optimizing Apps for Android 3.0</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/ui_guidelines/index.html">
               <span class="en">UI Guidelines</span>
             </a></div>
        <ul>
          <li class="toggle-list">
            <div><a href="../../../guide/practices/ui_guidelines/icon_design.html">
                   <span class="en">Icon Design <span class="new">updated</span></span>
                 </a></div>
            <ul>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_launcher.html">
                    <span class="en">Launcher Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_menu.html">
                    <span class="en">Menu Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_action_bar.html">
                    <span class="en">Action Bar Icons <span class="new">new!</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_status_bar.html">
                    <span class="en">Status Bar Icons <span class="new">updated</span></span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_tab.html">
                    <span class="en">Tab Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_dialog.html">
                    <span class="en">Dialog Icons</span>
                  </a></li>
              <li><a href="../../../guide/practices/ui_guidelines/icon_design_list.html">
                    <span class="en">List View Icons</span>
                  </a></li>
            </ul>
          </li>
          <li><a href="../../../guide/practices/ui_guidelines/widget_design.html">
                <span class="en">App Widget Design <span class="new">updated</span></span>
              </a></li>
          <li><a href="../../../guide/practices/ui_guidelines/activity_task_design.html">
                <span class="en">Activity and Task Design</span>
              </a></li>
          <li><a href="../../../guide/practices/ui_guidelines/menu_design.html">
                <span class="en">Menu Design</span>
              </a></li>
        </ul>
      </li>
      </ul>
      <ul>
      <li><a href="../../../guide/practices/design/accessibility.html">
            <span class="en">Designing for Accessibility</span>
          </a></li>
      <li class="toggle-list">
        <div><a href="../../../guide/practices/design/performance.html">
            <span class="en">Designing for Performance</span>
          </a></div>
        <ul>
          <li><a href="../../../guide/practices/design/jni.html">
                <span class="en">JNI Tips</span>
              </a></li>
        </ul>
      </li>
      <li><a href="../../../guide/practices/design/responsiveness.html">
            <span class="en">Designing for Responsiveness</span>
          </a></li>
      <li><a href="../../../guide/practices/design/seamlessness.html">
            <span class="en">Designing for Seamlessness</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Web Applications</span>
    </h2>
    <ul>
      <li><a href="../../../guide/webapps/index.html">
            <span class="en">Web Apps Overview</span>
          </a></li>
      <li><a href="../../../guide/webapps/targeting.html">
            <span class="en">Targeting Screens from Web Apps</span>
          </a></li>
      <li><a href="../../../guide/webapps/webview.html">
            <span class="en">Building Web Apps in WebView</span>
          </a></li>
      <li><a href="../../../guide/webapps/debugging.html">
            <span class="en">Debugging Web Apps</span>
          </a></li>
      <li><a href="../../../guide/webapps/best-practices.html">
            <span class="en">Best Practices for Web Apps</span>
          </a></li>
    </ul>
  </li>

  <li>
    <h2><span class="en">Appendix</span>
               <span class="de" style="display:none">Anhang</span>
               <span class="es" style="display:none">Apéndice</span>
               <span class="fr" style="display:none">Annexes</span>
               <span class="it" style="display:none">Appendice</span>
               <span class="ja" style="display:none">付録</span>
               <span class="zh-CN" style="display:none">附录</span>
               <span class="zh-TW" style="display:none">附錄</span>
    </h2>
    <ul>
      <li><a href="../../../guide/appendix/api-levels.html">
            <span class="en">Android API Levels</span>
          </a></li>
      <li><a href="../../../guide/appendix/install-location.html">
            <span class="en">App Install Location</span>
          </a></li>
      <li><a href="../../../guide/appendix/media-formats.html">
            <span class="en">Supported Media Formats <span class="new">updated</span></span>
          </a></li>
      <li><a href="../../../guide/appendix/g-app-intents.html">
            <span class="en">Intents List: Google Apps</span>
          </a></li>
      <li><a href="../../../guide/developing/tools/aidl.html">AIDL</a></li>
      <li><a href="../../../guide/appendix/glossary.html">
            <span class="en">Glossary</span>
          </a></li>
    </ul>
  </li>

</ul>

<script type="text/javascript">
<!--
    buildToggleLists();
    changeNavLang(getLangPref());
//-->
</script>

      </div>
    </div> <!-- end side-nav -->
    <script>
      addLoadEvent(function() {
        scrollIntoView("devdoc-nav");
        });
    </script>




<div class="g-unit" id="doc-content"><a name="top"></a>

<div id="jd-header" class="guide-header">
  <span class="crumb">
    &nbsp;
    
  </span>
<h1>Copy and Paste</h1>
</div>

  <div id="jd-content">

    <div class="jd-descr">
    <div id="qv-wrapper">
    <div id="qv">
        <h2>Quickview</h2>
            <ul>
                <li>
                    A clipboard-based framework for copying and pasting data.
                </li>
                <li>
                    Supports both simple and complex data, including text strings, complex data
                    structures, text and binary stream data, and application assets.
                </li>
                <li>
                    Copies and pastes simple text directly to and from the clipboard.
                </li>
                <li>
                    Copies and pastes complex data using a content provider.
                </li>
                <li>
                    Requires API 11.
                </li>
            </ul>
        <h2>In this document</h2>
        <ol>
            <li>
                <a href="#Clipboard">The Clipboard Framework</a>
            </li>
            <li>
                <a href="#ClipboardClasses">Clipboard Classes</a>
                <ol>
                    <li>
                        <a href="#ClipboardManager">ClipboardManager</a>
                    </li>
                    <li>
                        <a href="#ClipClasses">
                            ClipData, ClipDescription, and ClipData.Item
                        </a>
                    </li>
                    <li>
                        <a href="#ClipDataMethods">ClipData convenience methods</a>
                    </li>
                    <li>
                        <a href="#CoerceToText">Coercing the clipboard data to text</a>
                    </li>
                </ol>
            </li>
            <li>
                <a href="#Copying">Copying to the Clipboard</a>
            </li>
            <li>
                <a href="#Pasting">Pasting from the Clipboard</a>
                <ol>
                    <li>
                        <a href="#PastePlainText">Pasting plain text</a>
                    </li>
                    <li>
                        <a href="#PasteContentUri">Pasting data from a content URI</a>
                    </li>
                    <li>
                        <a href="#PasteIntent">Pasting an Intent</a>
                    </li>
                </ol>
            </li>
            <li>
                <a href="#Provider">Using Content Providers to Copy Complex Data</a>
                <ol>
                    <li>
                        <a href="#Encoding">Encoding an identifier on the URI</a>
                    </li>
                    <li>
                        <a href="#Records">Copying data structures</a>
                    </li>
                    <li>
                        <a href="#Streams">Copying data streams</a>
                    </li>
                </ol>
            </li>
            <li>
                <a href="#DataDesign">Designing Effective Copy/Paste Functionality</a>
            </li>
        </ol>
        <h2>Key classes</h2>
        <ol>
            <li>
                <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/net/Uri.html">Uri</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/content/ContentProvider.html">ContentProvider</a></code>
            </li>
            <li>
                <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>
            </li>
        </ol>
        <h2>Related Samples</h2>
        <ol>
            <li>
                <a href="../../../resources/samples/NotePad/index.html">
                Note Pad sample application</a>
            </li>
        </ol>
        <h2>See also</h2>
        <ol>
            <li>
            <a href="../../../guide/topics/providers/content-providers.html">Content Providers</a>
            </li>
        </ol>
    </div>
</div>
<p>
    Android provides a powerful clipboard-based framework for copying and pasting. It
    supports both simple and complex data types, including text strings, complex data
    structures, text and binary stream data, and even application assets. Simple text data is stored
    directly in the clipboard, while complex data is stored as a reference that the pasting
    application resolves with a content provider. Copying and pasting works both within an
    application and between applications that implement the framework.
</p>

<p>
    Since a part of the framework uses content providers, this topic assumes some
    familiarity with the Android Content Provider API, which is described in the topic
    <a href="../../../guide/topics/providers/content-providers.html">Content Providers</a>.
</p>
<h2 id="Clipboard">The Clipboard Framework</h2>
<p>
    When you use the clipboard framework, you put data into a clip object, and then
    put the clip object on the system-wide clipboard. The clip object can take one of three forms:
</p>
    <dl>
        <dt>Text</dt>
        <dd>
            A text string. You put the string directly into the clip object, which you then put onto
            the clipboard. To paste the string, you get the clip object from the clipboard and copy
            the string to into your application's storage.
        </dd>
        <dt>URI</dt>
        <dd>
            A <code><a href="../../../reference/android/net/Uri.html">Uri</a></code> object representing any form of URI. This is primarily for
            copying complex data from a content provider. To copy data, you put a
            <code><a href="../../../reference/android/net/Uri.html">Uri</a></code> object into a clip object and put the clip object onto
            the clipboard. To paste the data, you get the clip object, get the
            <code><a href="../../../reference/android/net/Uri.html">Uri</a></code> object, resolve it to a data source such as a content provider,
            and copy the data from the source into your application's storage.
        </dd>
        <dt>Intent</dt>
        <dd>
            An <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>. This supports copying application shortcuts. To copy
            data, you create an Intent, put it into a clip object, and put the clip object onto the
            clipboard. To paste the data, you get the clip object and then copy the Intent object
            into your application's memory area.
        </dd>
    </dl>
<p>
    The clipboard holds only one clip object at a time. When an application puts a clip object on
    the clipboard, the previous clip object disappears.
</p>
<p>
    If you want to allow users to paste data into your application, you don't have to handle all
    types of data. You can examine the data on the clipboard before you give users the option to
    paste it. Besides having a certain data form, the clip object also contains metadata that tells
    you what MIME type or types are available. This metadata helps you decide if your application
    can do something useful with the clipboard data. For example, if you have an application that
    primarily handles text you may want to ignore clip objects that contain a URI or Intent.
</p>
<p>
    You may also want to allow users to paste text regardless of the form of data on the
    clipboard. To do this, you can force the clipboard data into a text representation, and then
    paste this text. This is described in the section <a href="#CoerceToText">Coercing the
    clipboard to text</a>.
</p>
<h2 id="ClipboardClasses">Clipboard Classes</h2>
<p>
    This section describes the classes used by the clipboard framework.
</p>
<h3 id="ClipboardManager">ClipboardManager</h3>
<p>
    In the Android system, the system clipboard is represented by the global
    <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code> class. You do not instantiate this
    class directly; instead, you get a reference to it by invoking
    <code><a href="../../../reference/android/content/Context.html#getSystemService(java.lang.String)">getSystemService(CLIPBOARD_SERVICE)</a></code>.
</p>
<h3 id="ClipClasses">ClipData, ClipData.Item, and ClipDescription</h3>
<p>
    To add data to the clipboard, you create a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object that
    contains both a description of the data and the data itself. The clipboard holds only one
    <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> at a time. A <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> contains a
    <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object and one or more
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> objects.
</p>
<p>
    A <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object contains metadata about the clip. In
    particular, it contains an array of available MIME types for the clip's data. When you put a
    clip on the clipboard, this array is available to pasting applications, which can examine it to
    see if they can handle any of available the MIME types.
</p>
<p>
    A <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object contains the text, URI, or Intent data:
</p>
<dl>
    <dt>Text</dt>
    <dd>
        A <code><a href="../../../reference/java/lang/CharSequence.html">CharSequence</a></code>.
    </dd>
    <dt>URI</dt>
    <dd>
        A <code><a href="../../../reference/android/net/Uri.html">Uri</a></code>. This usually contains a content provider URI, although any
        URI is allowed. The application that provides the data puts the URI on the clipboard.
        Applications that want to paste the data get the URI from the clipboard and use it to
        access the content provider (or other data source) and retrieve the data.
    </dd>
    <dt>Intent</dt>
    <dd>
        An <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>. This data type allows you to copy an application shortcut
        to the clipboard. Users can then paste the shortcut into their applications for later use.
    </dd>
</dl>
<p>
    You can add more than one <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object to a clip. This allows
    users to copy and paste multiple selections as a single clip. For example, if you have a list
    widget that allows the user to select more than one item at a time, you can copy all the items
    to the clipboard at once. To do this, you create a separate
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> for each list item, and then you add the
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> objects to the <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object.
</p>
<h3 id="ClipDataMethods">ClipData convenience methods</h3>
<p>
    The <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> class provides static convenience methods for creating
    a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object with a single <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code>
    object and a simple <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object:
</p>
<dl>
    <dt>
<code><a href="../../../reference/android/content/ClipData.html#newPlainText(java.lang.CharSequence, java.lang.CharSequence)">newPlainText(label, text)</a></code>
    </dt>
    <dd>
        Returns a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object whose single
        <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object contains a text string. The
        <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object's label is set to <code>label</code>.
        The single MIME type in <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> is
        <code><a href="../../../reference/android/content/ClipDescription.html#MIMETYPE_TEXT_PLAIN">MIMETYPE_TEXT_PLAIN</a></code>.
        <p>
            Use
<code><a href="../../../reference/android/content/ClipData.html#newPlainText(java.lang.CharSequence, java.lang.CharSequence)">newPlainText()</a></code>
            to create a clip from a text string.
    </dd>
    <dt>
<code><a href="../../../reference/android/content/ClipData.html#newUri(android.content.ContentResolver, java.lang.CharSequence, android.net.Uri)">newUri(resolver, label, URI)</a></code>
    </dt>
    <dd>
        Returns a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object whose single
        <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object contains a URI. The
        <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object's label is set to <code>label</code>.
        If the URI is a content URI (<code><a href="../../../reference/android/net/Uri.html#getScheme()">Uri.getScheme()</a></code> returns
        <code>content:</code>), the method uses the <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> object
        provided in <code>resolver</code> to retrieve the available MIME types from the
        content provider and store them in <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code>. For a URI that
        is not a <code>content:</code> URI, the method sets the MIME type to
        <code><a href="../../../reference/android/content/ClipDescription.html#MIMETYPE_TEXT_URILIST">MIMETYPE_TEXT_URILIST</a></code>.
        <p>
            Use
<code><a href="../../../reference/android/content/ClipData.html#newUri(android.content.ContentResolver, java.lang.CharSequence, android.net.Uri)">newUri()</a></code>
            to create a clip from a URI, particularly a <code>content:</code> URI.
        </p>
    </dd>
    <dt>
        <code><a href="../../../reference/android/content/ClipData.html#newIntent(java.lang.CharSequence, android.content.Intent)">newIntent(label, intent)</a></code>
    </dt>
    <dd>
        Returns a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object whose single
        <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object contains an <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>.
        The <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object's label is set to <code>label</code>.
        The MIME type is set to <code><a href="../../../reference/android/content/ClipDescription.html#MIMETYPE_TEXT_INTENT">MIMETYPE_TEXT_INTENT</a></code>.
        <p>
            Use
<code><a href="../../../reference/android/content/ClipData.html#newIntent(java.lang.CharSequence, android.content.Intent)">newIntent()</a></code>
            to create a clip from an Intent object.
    </dd>
</dl>
<h3 id="CoerceToText">Coercing the clipboard data to text</h3>
<p>
    Even if your application only handles text, you can copy non-text data from the
    clipboard by converting it with the method
    <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">ClipData.Item.coerceToText()</a></code>.
</p>
<p>
    This method converts the data in <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> to text and
    returns a <code><a href="../../../reference/java/lang/CharSequence.html">CharSequence</a></code>. The value that
    <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">ClipData.Item.coerceToText()</a></code>
    returns is based on the form of data in <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code>:
</p>
<dl>
    <dt><em>Text</em></dt>
    <dd>
        If <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> is text
        (<code><a href="../../../reference/android/content/ClipData.Item.html#getText()">getText()</a></code> is not null),
        <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> returns the
        text.
    </dd>
    <dt><em>URI</em></dt>
    <dd>
        If <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> is a URI
        (<code><a href="../../../reference/android/content/ClipData.Item.html#getUri()">getUri()</a></code> is not null),
        <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> tries to use
        it as a content URI:
    <ul>
        <li>
                If the URI is a content URI and the provider can return a text stream,
                <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> returns
                a text stream.
            </li>
            <li>
                If the URI is a content URI but the provider does not offer a text stream,
                <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> returns
                a representation of the URI. The representation is the same as that returned by
                <code><a href="../../../reference/android/net/Uri.html#toString()">Uri.toString()</a></code>.
            </li>
            <li>
                If the URI is not a content URI,
                <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> returns
                a representation of the URI. The representation is the same as that returned by
                <code><a href="../../../reference/android/net/Uri.html#toString()">Uri.toString()</a></code>.
            </li>
        </ul>
    </dd>
    <dt><em>Intent</em></dt>
    <dd>
        If <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> is an Intent
        (<code><a href="../../../reference/android/content/ClipData.Item.html#getIntent()">getIntent()</a></code> is not null),
        <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> converts it to
        an Intent URI and returns it. The representation is the same as that returned by
        <code><a href="../../../reference/android/content/Intent.html#toUri(int)">Intent.toUri(URI_INTENT_SCHEME)</a></code>.
    </dd>
</dl>
<p>
    The clipboard framework is summarized in Figure 1. To copy data, an application puts a
    <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object on the <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code> global
    clipboard. The <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> contains one or more
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> objects and one
    <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> object. To paste data, an application gets the
    <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code>, gets its MIME type from the
    <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code>, and gets the data either from
    the <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> or from the content provider referred to by
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code>.
</p>
    <a name="framework"></a>
    <img
        src="../../../images/ui/clipboard/copy_paste_framework.png"
        alt="A block diagram of the copy and paste framework" height="400px" id="figure1" />
<p class="img-caption">
    <strong>Figure 1.</strong> The Android clipboard framework
</p>
<h2 id="Copying">Copying to the Clipboard</h2>
<p>
    As described previously, to copy data to the clipboard you get a handle to the global
    <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code> object, create a <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code>
    object, add a <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code> and one or more
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> objects to it, and add the finished
    <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object to the <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code> object.
    This is described in detail in the following procedure:
</p>
<ol>
    <li>
        If you are copying data using a content URI, set up a content
        provider.
        <p>
            The <a href="../../../resources/samples/NotePad/index.html">
            Note Pad</a> sample application is an example of using a content provider for
            copying and pasting. The
<a href="../../../resources/samples/NotePad/src/com/example/android/notepad/NotePadProvider.html">
            NotePadProvider</a> class implements the content provider. The
<a href="../../../resources/samples/NotePad/src/com/example/android/notepad/NotePad.html">
            NotePad</a> class defines a contract between the provider and other applications,
            including the supported MIME types.
        </p>
    </li>
    <li>
        Get the system clipboard:
<pre>

...

// if the user selects copy
case R.id.menu_copy:

// Gets a handle to the clipboard service.
ClipboardManager clipboard = (ClipboardManager)
        getSystemService(Context.CLIPBOARD_SERVICE);
</pre>
    </li>
    <li>
        <p>
            Copy the data to a new <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object:
        </p>
        <ul>
            <li>
                <h4>For text</h4>
<pre>
// Creates a new text clip to put on the clipboard
ClipData clip = ClipData.newPlainText(&quot;simple text&quot;,&quot;Hello, World!&quot;);
</pre>
            </li>
            <li>
                <h4>For a URI</h4>
                <p>
                    This snippet constructs a URI by encoding a record ID onto the content URI
                    for the provider. This technique is covered in more detail
                    in the section <a href="#Encoding">Encoding an identifier on the URI</a>:
                </p>
<pre>
// Creates a Uri based on a base Uri and a record ID based on the contact's last name
// Declares the base URI string
private static final String CONTACTS = &quot;content:&#47;&#47;com.example.contacts&quot;;

// Declares a path string for URIs that you use to copy data
private static final String COPY_PATH = &quot;/copy&quot;;

// Declares the Uri to paste to the clipboard
Uri copyUri = Uri.parse(CONTACTS + COPY_PATH + &quot;/&quot; + lastName);

...

// Creates a new URI clip object. The system uses the anonymous getContentResolver() object to
// get MIME types from provider. The clip object's label is &quot;URI&quot;, and its data is
// the Uri previously created.
ClipData clip = ClipData.newUri(getContentResolver(),&quot;URI&quot;,copyUri);
</pre>
            </li>
            <li>
                <h4>For an Intent</h4>
                <p>
                    This snippet constructs an Intent for an application
                    and then puts it in the clip object:
                </p>
<pre>
// Creates the Intent
Intent appIntent = new Intent(this, com.example.demo.myapplication.class);

...

// Creates a clip object with the Intent in it. Its label is &quot;Intent&quot; and its data is
// the Intent object created previously
ClipData clip = ClipData.newIntent(&quot;Intent&quot;,appIntent);
</pre>
            </li>
        </ul>
    </li>
    <li>
        Put the new clip object on the clipboard:
<pre>
// Set the clipboard's primary clip.
clipboard.setPrimaryClip(clip);
</pre>
    </li>
</ol>
<h2 id="Pasting">Pasting from the Clipboard</h2>
<p>
    As described previously, you paste data from the clipboard by getting the global clipboard
    object, getting the clip object, looking at its data, and if possible copying the data from
    the clip object to your own storage. This section describes in detail how to do this for
    the three forms of clipboard data.
</p>
<h3 id="PastePlainText">Pasting plain text</h3>
<p>
    To paste plain text, first get the global clipboard and verify that it can return plain text.
    Then get the clip object and copy its text to your own storage using
    <code><a href="../../../reference/android/content/ClipData.Item.html#getText()">getText()</a></code>, as described in the following procedure:
</p>
<ol>
    <li>
        Get the global <code><a href="../../../reference/android/content/ClipboardManager.html">ClipboardManager</a></code> object using
 <code><a href="../../../reference/android/content/Context.html#getSystemService(java.lang.String)">getSystemService(CLIPBOARD_SERVICE)</a></code>. Also
        declare a global variable to contain the pasted text:
<pre>
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

String pasteData = &quot;&quot;;

</pre>
    </li>
    <li>
        Next, determine if you should enable or disable the &quot;paste&quot; option in the
        current Activity. You should verify that the clipboard contains a clip and that you
        can handle the type of data represented by the clip:
<pre>
// Gets the ID of the &quot;paste&quot; menu item
MenuItem mPasteItem = menu.findItem(R.id.menu_paste);

// If the clipboard doesn't contain data, disable the paste menu item.
// If it does contain data, decide if you can handle the data.
if (!(clipboard.hasPrimaryClip())) {

    mPasteItem.setEnabled(false);

    } else if (!(clipboard.getPrimaryClipDescription().hasMimeType(MIMETYPE_TEXT_PLAIN))) {

        // This disables the paste menu item, since the clipboard has data but it is not plain text
        mPasteItem.setEnabled(false);
    } else {

        // This enables the paste menu item, since the clipboard contains plain text.
        mPasteItem.setEnabled(true);
    }
}
</pre>
    </li>
    <li>
        Copy the data from the clipboard. This point in the program is only reachable if the
        &quot;paste&quot; menu item is enabled, so you can assume that the clipboard contains
        plain text. You do not yet know if it contains a text string or a URI that points to plain
        text. The following snippet tests this, but it only shows the code for handling plain text:
<pre>
// Responds to the user selecting &quot;paste&quot;
case R.id.menu_paste:

// Examines the item on the clipboard. If getText() does not return null, the clip item contains the
// text. Assumes that this application can only handle one item at a time.
 ClipData.Item item = clipboard.getPrimaryClip().getItemAt(0);

// Gets the clipboard as text.
pasteData = item.getText();

// If the string contains data, then the paste operation is done
if (pasteData != null) {
    return;

// The clipboard does not contain text. If it contains a URI, attempts to get data from it
} else {
    Uri pasteUri = item.getUri();

    // If the URI contains something, try to get text from it
    if (pasteUri != null) {

        // calls a routine to resolve the URI and get data from it. This routine is not
        // presented here.
        pasteData = resolveUri(Uri);
        return;
    } else {

    // Something is wrong. The MIME type was plain text, but the clipboard does not contain either
    // text or a Uri. Report an error.
    Log.e(&quot;Clipboard contains an invalid data type&quot;);
    return;
    }
}
</pre>
    </li>
</ol>
<h3 id="PasteContentUri">Pasting data from a content URI</h3>
<p>
    If the <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object contains a content URI and you
    have determined that you can handle one of its MIME types, create a
    <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> and then call the appropriate content provider
    method to retrieve the data.
</p>
<p>
    The following procedure describes how to get data from a content provider based on a
    content URI on the clipboard. It checks that a MIME type that the application can use
    is available from the provider:
</p>
<ol>
    <li>
        Declare a global variable to contain the MIME type:
<pre>
// Declares a MIME type constant to match against the MIME types offered by the provider
public static final String MIME_TYPE_CONTACT = &quot;vnd.android.cursor.item/vnd.example.contact&quot;
</pre>
    </li>
    <li>
        Get the global clipboard. Also get a content resolver so you can access the content
        provider:
<pre>
// Gets a handle to the Clipboard Manager
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

// Gets a content resolver instance
ContentResolver cr = getContentResolver();
</pre>
    </li>
    <li>
        Get the primary clip from the clipboard, and get its contents as a URI:
<pre>
// Gets the clipboard data from the clipboard
ClipData clip = clipboard.getPrimaryClip();

if (clip != null) {

    // Gets the first item from the clipboard data
    ClipData.Item item = clip.getItemAt(0);

    // Tries to get the item's contents as a URI
    Uri pasteUri = item.getUri();
</pre>
    </li>
    <li>
        Test to see if the URI is a content URI by calling
        <code><a href="../../../reference/android/content/ContentResolver.html#getType(android.net.Uri)">getType(Uri)</a></code>. This method returns
        null if <code>Uri</code> does not point to a valid content provider:
<pre>
    // If the clipboard contains a URI reference
    if (pasteUri != null) {

        // Is this a content URI?
        String uriMimeType = cr.getType(pasteUri);
</pre>
    </li>
    <li>
        Test to see if the content provider supports a MIME type that the current application
        understands. If it does, call
        <code><a href="../../../reference/android/content/ContentResolver.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)">ContentResolver.query()</a></code> to get the data. The return value is a
        <code><a href="../../../reference/android/database/Cursor.html">Cursor</a></code>:
<pre>
        // If the return value is not null, the Uri is a content Uri
        if (uriMimeType != null) {

            // Does the content provider offer a MIME type that the current application can use?
            if (uriMimeType.equals(MIME_TYPE_CONTACT)) {

                // Get the data from the content provider.
                Cursor pasteCursor = cr.query(uri, null, null, null, null);

                // If the Cursor contains data, move to the first record
                if (pasteCursor != null) {
                    if (pasteCursor.moveToFirst()) {

                    // get the data from the Cursor here. The code will vary according to the
                    // format of the data model.
                    }
                }

                // close the Cursor
                pasteCursor.close();
             }
         }
     }
}
</pre>
    </li>
</ol>
<h3 id="PasteIntent">Pasting an Intent</h3>
<p>
    To paste an Intent, first get the global clipboard. Examine the
    <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> object to see if it contains an Intent. Then call
    <code><a href="../../../reference/android/content/ClipData.Item.html#getIntent()">getIntent()</a></code> to copy the Intent to your own storage.
    The following snippet demonstrates this:
</p>
<pre>
// Gets a handle to the Clipboard Manager
ClipboardManager clipboard = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);

// Checks to see if the clip item contains an Intent, by testing to see if getIntent() returns null
Intent pasteIntent = clipboard.getPrimaryClip().getItemAt(0).getIntent();

if (pasteIntent != null) {

    // handle the Intent

} else {

    // ignore the clipboard, or issue an error if your application was expecting an Intent to be
    // on the clipboard
}
</pre>
<h2 id="Provider">Using Content Providers to Copy Complex Data</h2>
<p>
    Content providers support copying complex data such as database records or file streams.
    To copy the data, you put a content URI on the clipboard. Pasting applications then get this
    URI from the clipboard and use it to retrieve database data or file stream descriptors.
</p>
<p>
    Since the pasting application only has the content URI for your data, it needs to know which
    piece of data to retrieve. You can provide this information by encoding an identifier for the
    data on the URI itself, or you can provide a unique URI that will return the data you want to
    copy. Which technique you choose depends on the organization of your data.
</p>
<p>
    The following sections describe how to set up URIs, how to provide complex data, and how to
    provide file streams. The descriptions assume that you are familiar with the general principles
    of content provider design.
</p>
<h3 id="Encoding">Encoding an identifier on the URI</h3>
<p>
    A useful technique for copying data to the clipboard with a URI is to encode an identifier for
    the data on the URI itself. Your content provider can then get the identifier from the URI and
    use it to retrieve the data. The pasting application doesn't have to know that the identifier
    exists; all it has to do is get your &quot;reference&quot; (the URI plus the identifier) from
    the clipboard, give it your content provider, and get back the data.
</p>
<p>
    You usually encode an identifier onto a content URI by concatenating it to the end of the URI.
    For example, suppose you define your provider URI as the following string:
</p>
<pre>
&quot;content://com.example.contacts&quot;
</pre>
<p>
   If you want to encode a name onto this URI, you would use the following snippet:
</p>
<pre>
String uriString = &quot;content:&#47;&#47;com.example.contacts&quot; + &quot;/&quot; + &quot;Smith&quot;

// uriString now contains content://com.example.contacts/Smith.

// Generates a uri object from the string representation
Uri copyUri = Uri.parse(uriString);
</pre>
<p>
    If you are already using a content provider, you may want to add a new URI path that indicates
    the URI is for copying. For example, suppose you already have the following URI paths:
</p>
<pre>
&quot;content://com.example.contacts&quot;/people
&quot;content://com.example.contacts&quot;/people/detail
&quot;content://com.example.contacts&quot;/people/images
</pre>
<p>
   You could add another path that is specific to copy URIs:
</p>
<pre>
&quot;content://com.example.contacts/copying&quot;
</pre>
<p>
    You could then detect a &quot;copy&quot; URI by pattern-matching and handle it with code that
    is specific for copying and pasting.
</p>
<p>
    You normally use the encoding technique if you're already using a content provider, internal
    database, or internal table to organize your data. In these cases, you have multiple pieces of
    data you want to copy, and presumably a unique identifier for each piece. In response to a
    query from the pasting application, you can look up the data by its identifier and return it.
</p>
<p>
    If you don't have multiple pieces of data, then you probably don't need to encode an identifier.
    You can simply use a URI that is unique to your provider. In response to a query, your provider
    would return the data it currently contains.
</p>
<p>
    Getting a single record by ID is used in the
    <a href="../../../resources/samples/NotePad/index.html">Note Pad</a> sample application to
    open a note from the notes list. The sample uses the <code>_id</code> field from an SQL
    database, but you can have any numeric or character identifier you want.
</p>
<h3 id="Records">Copying data structures</h3>
<p>
    You set up a content provider for copying and pasting complex data as a subclass of the
    <code><a href="../../../reference/android/content/ContentProvider.html">ContentProvider</a></code> component. You should also encode the URI you put on
    the clipboard so that it points to the exact record you want to provide. In addition, you
    have to consider the existing state of your application:
</p>
<ul>
    <li>
        If you already have a content provider, you can add to its functionality. You may only
        need to modify its
<code><a href="../../../reference/android/content/ContentResolver.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)">query()</a></code>
        method to handle URIs coming from applications that want to paste data. You will
        probably want to modify the method to handle a &quot;copy&quot; URI pattern.
    </li>
    <li>
        If your application maintains an internal database, you may
        want to move this database into a content provider to facilitate copying from it.
    </li>
    <li>
        If you are not currently using a database, you can implement a simple content provider
        whose sole purpose is to offer data to applications that are pasting from the
        clipboard.
    </li>
</ul>
<p>
In the content provider, you will want to override at least the following methods:
</p>
<dl>
    <dt>
<code><a href="../../../reference/android/content/ContentResolver.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)">query()</a></code>
    </dt>
    <dd>
        Pasting applications will assume that they can get your data by using this method with
        the URI you put on the clipboard. To support copying, you should have this method
        detect URIs that contain a special &quot;copy&quot; path. Your application can then
        create a &quot;copy&quot; URI to put on the clipboard, containing the copy path and
        a pointer to the exact record you want to copy.
    </dd>
    <dt>
        <code><a href="../../../reference/android/content/ContentProvider.html#getType(android.net.Uri)">getType()</a></code>
    </dt>
    <dd>
        This method should return the MIME type or types for the data you intend to copy. The method
        <code><a href="../../../reference/android/content/ClipData.html#newUri(android.content.ContentResolver, java.lang.CharSequence, android.net.Uri)">newUri()</a></code> calls
        <code><a href="../../../reference/android/content/ContentProvider.html#getType(android.net.Uri)">getType()</a></code> in order to put the MIME
        types into the new <code><a href="../../../reference/android/content/ClipData.html">ClipData</a></code> object.
        <p>
            MIME types for complex data are described in the topic
            <a href="../../../guide/topics/providers/content-providers.html">Content Providers</a>.
        </p>
    </dd>
</dl>
<p>
    Notice that you don't have to have any of the other content provider methods such as
    <code><a href="../../../reference/android/content/ContentProvider.html#insert(android.net.Uri, android.content.ContentValues)">insert()</a></code> or
    <code><a href="../../../reference/android/content/ContentProvider.html#update(android.net.Uri, android.content.ContentValues, java.lang.String, java.lang.String[])">update()</a></code>.
    A pasting application only needs to get your supported MIME types and copy data from your
    provider. If you already have these methods, they won't interfere with copy operations.
</p>
<p>
    The following snippets demonsrate how to set up your application to copy complex data:
</p>
<ol>
    <li>
        <p>
            In the global constants for your application,
            declare a base URI string and a path that identifies URI strings you are
            using to copy data. Also declare a MIME type for the copied data:
        </p>
<pre>
// Declares the base URI string
private static final String CONTACTS = &quot;content:&#47;&#47;com.example.contacts&quot;;

// Declares a path string for URIs that you use to copy data
private static final String COPY_PATH = &quot;/copy&quot;;

// Declares a MIME type for the copied data
public static final String MIME_TYPE_CONTACT = &quot;vnd.android.cursor.item/vnd.example.contact&quot;
</pre>
    </li>
    <li>
        In the Activity from which users copy data,
        set up the code to copy data to the clipboard. In response to a copy request, put
        the URI on the clipboard:
<pre>
public class MyCopyActivity extends Activity {

    ...

// The user has selected a name and is requesting a copy.
case R.id.menu_copy:

    // Appends the last name to the base URI
    // The name is stored in &quot;lastName&quot;
    uriString = CONTACTS + COPY_PATH + &quot;/&quot; + lastName;

    // Parses the string into a URI
    Uri copyUri = Uri.parse(uriString);

    // Gets a handle to the clipboard service.
    ClipboardManager clipboard = (ClipboardManager)
        getSystemService(Context.CLIPBOARD_SERVICE);

    ClipData clip = ClipData.newUri(getContentResolver(), &quot;URI&quot;, copyUri);

    // Set the clipboard's primary clip.
    clipboard.setPrimaryClip(clip);
</pre>
    </li>

    <li>
    <p>
        In the global scope of your content provider, create a URI matcher and add a URI
        pattern that will match URIs you put on the clipboard:
    </p>
<pre>
public class MyCopyProvider extends ContentProvider {

    ...

// A Uri Match object that simplifies matching content URIs to patterns.
private static final UriMatcher sURIMatcher = new UriMatcher(UriMatcher.NO_MATCH);

// An integer to use in switching based on the incoming URI pattern
private static final int GET_SINGLE_CONTACT = 0;

...

// Adds a matcher for the content URI. It matches
// &quot;content://com.example.contacts/copy/*&quot;
sUriMatcher.addURI(CONTACTS, "names/*", GET_SINGLE_CONTACT);
</pre>
    </li>
    <li>
    <p>
        Set up the
     <code><a href="../../../reference/android/content/ContentProvider.html#query(android.net.Uri, java.lang.String[], java.lang.String, java.lang.String[], java.lang.String)">query()</a></code>
        method. This method can handle different URI patterns, depending on how you code it, but
        only the pattern for the clipboard copying operation is shown:
    </p>
<pre>
// Sets up your provider's query() method.
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
    String sortOrder) {

    ...

    // Switch based on the incoming content URI
    switch (sUriMatcher.match(uri)) {

    case GET_SINGLE_CONTACT:

        // query and return the contact for the requested name. Here you would decode
        // the incoming URI, query the data model based on the last name, and return the result
        // as a Cursor.

    ...

}
</pre>
    </li>
    <li>
        <p>
            Set up the <code><a href="../../../reference/android/content/ContentProvider.html#getType(android.net.Uri)">getType()</a></code> method to
            return an appropriate MIME type for copied data:
        </p>
<pre>
// Sets up your provider's getType() method.
public String getType(Uri uri) {

    ...

    switch (sUriMatcher.match(uri)) {

    case GET_SINGLE_CONTACT:

            return (MIME_TYPE_CONTACT);
</pre>
    </li>
</ol>
<p>
    The section <a href="#PasteContentUri">Pasting data from a content URI</a>
    describes how to get a content URI from the clipboard and use it to get and paste data.
</p>
<h3 id="Streams">Copying data streams</h3>
<p>
    You can copy and paste large amounts of text and binary data as streams. The data can have
    forms such as the following:
</p>
    <ul>
        <li>
            Files stored on the actual device.
        </li>
        <li>
            Streams from sockets.
        </li>
        <li>
            Large amounts of data stored in a provider's underlying database system.
        </li>
    </ul>
<p>
    A content provider for data streams provides access to its data with a file descriptor object
    such as <code><a href="../../../reference/android/content/res/AssetFileDescriptor.html">AssetFileDescriptor</a></code> instead of a
    <code><a href="../../../reference/android/database/Cursor.html">Cursor</a></code> object. The pasting application reads the data stream using
    this file descriptor.
</p>
<p>
    To set up your application to copy a data stream with a provider, follow these steps:
</p>
<ol>
    <li>
        Set up a content URI for the data stream you are putting on the clipboard. Options
        for doing this include the following:
        <ul>
            <li>
                Encode an identifier for the data stream onto the URI,
                as described in the section
                <a href="#Encoding">Encoding an identifier on the URI</a>, and then maintain a
                table in your provider that contains identifiers and the corresponding stream name.
            </li>
            <li>
                Encode the stream name directly on the URI.
            </li>
            <li>
                Use a unique URI that always returns the current stream from the provider. If you
                use this option, you have to remember to update your provider to point to a
                different stream whenever you copy the stream to the clipboard via the URI.
            </li>
        </ul>
    </li>
    <li>
        Provide a MIME type for each type of data stream you plan to offer. Pasting applications
        need this information to determine if they can paste the data on the clipboard.
    </li>
    <li>
        Implement one of the <code><a href="../../../reference/android/content/ContentProvider.html">ContentProvider</a></code> methods that returns
        a file descriptor for a stream. If you encode identifiers on the content URI, use this
        method to determine which stream to open.
    </li>
    <li>
        To copy the data stream to the clipboard, construct the content URI and place it
        on the clipboard.
    </li>
</ol>
<p>
    To paste a data stream, an application gets the clip from the clipboard, gets the URI, and
    uses it in a call to a <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> file descriptor method that
    opens the stream. The <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> method calls the corresponding
    <code><a href="../../../reference/android/content/ContentProvider.html">ContentProvider</a></code> method, passing it the content URI. Your provider
    returns the file descriptor to <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> method. The pasting
    application then has the responsibility to read the data from the stream.
</p>
<p>
    The following list shows the most important file descriptor methods for a content provider.
    Each of these has a corresponding <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> method with the
    string &quot;Descriptor&quot; appended to the method name; for example, the
    <code><a href="../../../reference/android/content/ContentResolver.html">ContentResolver</a></code> analog of
    <code><a href="../../../reference/android/content/ContentProvider.html#openAssetFile(android.net.Uri, java.lang.String)">openAssetFile()</a></code> is
<code><a href="../../../reference/android/content/ContentResolver.html#openAssetFileDescriptor(android.net.Uri, java.lang.String)">openAssetFileDescriptor()</a></code>:
</p>
<dl>
    <dt>
<code><a href="../../../reference/android/content/ContentProvider.html#openTypedAssetFile(android.net.Uri, java.lang.String, android.os.Bundle)">openTypedAssetFile()</a></code>
    </dt>
    <dd>
        This method should return an asset file descriptor, but only if the provided MIME type is
        supported by the provider. The caller (the application doing the pasting) provides a MIME
        type pattern. The content provider (of the application that has copied a URI to the
        clipboard) returns an <code><a href="../../../reference/android/content/res/AssetFileDescriptor.html">AssetFileDescriptor</a></code> file handle if it
        can provide that MIME type, or throws an exception if it can not.
        <p>
            This method handles subsections of files. You can use it to read assets that the
            content provider has copied to the clipboard.
        </p>
    </dd>
    <dt>
        <code><a href="../../../reference/android/content/ContentProvider.html#openAssetFile(android.net.Uri, java.lang.String)">openAssetFile()</a></code>
    </dt>
    <dd>
        This method is a more general form of
<code><a href="../../../reference/android/content/ContentProvider.html#openTypedAssetFile(android.net.Uri, java.lang.String, android.os.Bundle)">openTypedAssetFile()</a></code>.
        It does not filter for allowed MIME types, but it can read subsections of files.
    </dd>
    <dt>
        <code><a href="../../../reference/android/content/ContentProvider.html#openFile(android.net.Uri, java.lang.String)">openFile()</a></code>
    </dt>
    <dd>
        This is a more general form of
        <code><a href="../../../reference/android/content/ContentProvider.html#openAssetFile(android.net.Uri, java.lang.String)">openAssetFile()</a></code>. It can't
        read subsections of files.
    </dd>
</dl>
<p>
    You can optionally use the
<code><a href="../../../reference/android/content/ContentProvider.html#openPipeHelper(android.net.Uri, java.lang.String, android.os.Bundle, T, android.content.ContentProvider.PipeDataWriter<T>)">openPipeHelper()</a></code>
    method with your file descriptor method. This allows the pasting application to read the
    stream data in a background thread using a pipe. To use this method, you need to implement the
    <code><a href="../../../reference/android/content/ContentProvider.PipeDataWriter.html">ContentProvider.PipeDataWriter</a></code> interface. An example of doing this is
    given in the <a href="../../../resources/samples/NotePad/index.html">Note Pad</a> sample
    application, in the <code>openTypedAssetFile()</code> method of
    <code>NotePadProvider.java</code>.
</p>
<h2 id="DataDesign">Designing Effective Copy/Paste Functionality</h2>
<p>
    To design effective copy and paste functionality for your application, remember these
    points:
</p>
    <ul>
        <li>
            At any time, there is only one clip on the clipboard. A new copy operation by
            any application in the system overwrites the previous clip. Since the user may
            navigate away from your application and do a copy before returning, you can't assume
            that the clipboard contains the clip that the user previously copied in <em>your</em>
            application.
        </li>
        <li>
            The intended purpose of multiple <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code>
            objects per clip is to support copying and pasting of multiple selections rather than
            different forms of reference to a single selection. You usually want all of the
           <code><a href="../../../reference/android/content/ClipData.Item.html">ClipData.Item</a></code> objects in a clip to have the same form, that is,
           they should all be simple text, content URI, or <code><a href="../../../reference/android/content/Intent.html">Intent</a></code>, but not
           a mixture.
        </li>
        <li>
            When you provide data, you can offer different MIME representations. Add the MIME types
            you support to the <code><a href="../../../reference/android/content/ClipDescription.html">ClipDescription</a></code>, and then
            implement the MIME types in your content provider.
        </li>
        <li>
            When you get data from the clipboard, your application is responsible for checking the
            available MIME types and then deciding which one, if any, to use. Even if there is a
            clip on the clipboard and the user requests a paste, your application is not required
            to do the paste. You <em>should</em> do the paste if the MIME type is compatible. You
            may choose to coerce the data on the clipboard to text using
            <code><a href="../../../reference/android/content/ClipData.Item.html#coerceToText(android.content.Context)">coerceToText()</a></code> if you
            choose. If your application supports more than one of the available MIME types, you can
            allow the user to choose which one to use.
        </li>
    </ul>

    </div>

  <a href="#top" style="float:right">&uarr; Go to top</a>
  
  </div>

<div id="footer">


  <div id="copyright">
    
  Except as noted, this content is licensed under <a
  href="http://www.apache.org/licenses/LICENSE-2.0">Apache 2.0</a>. 
  For details and restrictions, see the <a href="../../../license.html">
  Content License</a>.
  </div>
  <div id="build_info">
    
  Android 4.0&nbsp;r1 - 17 Oct 2011 18:17

  </div>

  <div id="footerlinks">
    
  <p>
    <a href="http://www.android.com/terms.html">Site Terms of Service</a> -
    <a href="http://www.android.com/privacy.html">Privacy Policy</a> -
    <a href="http://www.android.com/branding.html">Brand Guidelines</a>
  </p>
  </div>

</div> <!-- end footer -->

</div><!-- end doc-content -->

</div> <!-- end body-content --> 

<script type="text/javascript">
init(); /* initialize android-developer-docs.js */
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-5831155-1");
pageTracker._trackPageview();
</script>

</body>
</html>



